package cn.tedu.sp03.controller;

import cn.tedu.sa01.pojo.User;
import cn.tedu.sa01.server.UserServer;
import cn.tedu.web.util.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class UserController {

    @Autowired
    private UserServer userServer;

    @GetMapping("/{userId}")
    public JsonResult<User> getuser(@PathVariable Integer userId ){
        User user = userServer.getUser(userId);
        return  JsonResult.ok().data(user);
    }

    @GetMapping("/{userId}/score")
    public JsonResult<?>addScore(@PathVariable Integer userId,Integer score){
        userServer.addScore(userId,score);
        return JsonResult.ok().msg("增加用户积分成功");
    }
}
